/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2024-02-03
 * Time: 10:54
 */
import java.util.Random;

public class Test4 {
    public static void main(String[] args) {
        Random rand = new Random();
        int[] num1 = new int[20];
        int[] num2 = new int[20];

        for (int i = 0; i < 20; i++) {
            num1[i] = rand.nextInt(10);
            num2[i] = rand.nextInt(10);
        }

        System.out.print("第一个20位随机整数为：");
        for (int i = 0; i < 20; i++) {
            System.out.print(num1[i]);
        }
        System.out.println();

        System.out.print("第二个20位随机整数为：");
        for (int i = 0; i < 20; i++) {
            System.out.print(num2[i]);
        }
        System.out.println();

        int[] sum = new int[21];
        int carry = 0;
        for (int i = 19; i >= 0; i--) {
            sum[i + 1] = num1[i] + num2[i] + carry;
            carry = sum[i + 1] / 10;
            sum[i + 1] %= 10;
        }
        sum[0] = carry;

        System.out.println("两个整数的求和结果为：");
        if (sum[0] == 0) {
            for (int i = 1; i <= 20; i++) {
                System.out.print(sum[i]);
            }
        } else {
            for (int i = 0; i <= 20; i++) {
                System.out.print(sum[i]);
            }
        }
        System.out.println();
    }
}